package com.example.demo;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;


@RestController
public class SpringBootWebController {
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Autowired
	private SpringBoot_Service springService;
	@RequestMapping(value="webTest")
	public ModelAndView webTest(){
		return new ModelAndView("index");
	}
	
	@RequestMapping(value="getMap")
	public Map<String,Object> getMap(){
		Map<String,Object>map=new HashMap<String,Object>();
		map.put("a","a22222");
		map.put("b",2222);
		map.put("c",3333);
		map.put("d",1);
		return map;
	}
	//不需要主动抛出异常，即可以捕捉到Controller和service层的异常
	@RequestMapping(value="GlobarException")
	public void GlobarException(HttpServletRequest request,String type,String param) {
		//springService.tException();
		springService.testSqlConnect(jdbcTemplate);
		if(type.equals("1")){
			
		}
		if(param.equals("1")){
			
		}
	}
}